﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;

namespace INF7GEN
{

    /// <summary>
    /// Represents a single thing type object.
    /// </summary>
    [Serializable()]
    public class Thing : ISerializable
    {
        private bool varies = false;
        private String internalName = "";
        private String printedName = "";
        private String pluralName = "";
        private String indefiniteArticle = "";
        private String inventoryListing = "";
        private int type = -1;
        private String customType = "";
        private Thing thingType = null;//the kind of thing this thing is
        private bool properNamed = false;
        private bool pluralNamed = false;
        private bool kindOf = false;





        public Thing()
        {
        }

        //--------------------------------------------------------------------
        //Serialization-------------------------------------------------------
        public Thing(SerializationInfo info, StreamingContext ctxt)
        {
            this.InternalName = (String)info.GetValue("THINGInternalName", typeof(String));
            this.PrintedName = (String)info.GetValue("THINGPrintedName", typeof(String));
            this.PluralName = (String)info.GetValue("THINGPluralName", typeof(String));
            this.IndefiniteArticle = (String)info.GetValue("THINGIndefiniteArticle", typeof(String));
            this.InventoryListing = (String)info.GetValue("THINGInventoryListing", typeof(String));
            this.Type = (int)info.GetValue("THINGType", typeof(int));
            this.PluralNamed = (bool)info.GetValue("THINGPluralNamed", typeof(bool));
            this.ProperNamed = (bool)info.GetValue("THINGProperNamed", typeof(bool));
            this.CustomType = (String)info.GetValue("THINGCustomType", typeof(String));
            this.ThingType = (Thing)info.GetValue("THINGThingType", typeof(Thing));
            this.KindOf = (bool)info.GetValue("THINGKindOf", typeof(bool));
            this.varies = (bool)info.GetValue("THINGVaries", typeof(bool));
        }

        public void GetObjectData(SerializationInfo info, StreamingContext ctxt)
        {
            info.AddValue("THINGInternalName", this.InternalName);
            info.AddValue("THINGPrintedName", this.PrintedName);
            info.AddValue("THINGPluralName", this.PluralName);
            info.AddValue("THINGIndefiniteArticle", this.IndefiniteArticle);
            info.AddValue("THINGInventoryListing", this.InventoryListing);
            info.AddValue("THINGType", this.Type);
            info.AddValue("THINGPluralNamed", this.PluralNamed);
            info.AddValue("THINGProperNamed", this.ProperNamed);
            info.AddValue("THINGCustomType", this.CustomType);
            info.AddValue("THINGThingType", this.ThingType);
            info.AddValue("THINGKindOf", this.KindOf);
            info.AddValue("THINGVaries", this.varies);
        }
        //-------------------------------------------------------------------




        public override string ToString()
        {
            string s = this.InternalName;
            if (type != -1)
                return GlobalStates.type[type] + " : " + s;
            else if (ThingType != null)
                return "Thing type " + ThingType.InternalName + " : " + s;
            else if (customType.Length > 0)
                return CustomType + " : " + s;
            else
                return s;
        }


        /// <summary>
        /// Thing boolean meaning name is proper
        /// </summary>
        public bool ProperNamed
        {
            get { return this.properNamed; }
            set { this.properNamed = value; }
        }

        /// <summary>
        /// Thing boolean if thing varies or changes instance.
        /// </summary>
        public bool Varies
        {
            get { return this.varies; }
            set { this.varies = value; }
        }

        /// <summary>
        /// Thing boolean meaning if this a abstract kind of
        /// </summary>
        public bool KindOf
        {
            get { return this.kindOf; }
            set { this.kindOf = value; }
        }

        /// <summary>
        /// Thing boolean meaning name is plural
        /// </summary>
        public bool PluralNamed
        {
            get { return this.pluralNamed; }
            set { this.pluralNamed = value; }
        }

        /// <summary>
        /// Thing object representing the type of thing this thing is.
        /// </summary>
        public Thing ThingType
        {
            get { return this.thingType; }
            set { this.thingType = value; }
        }


        /// <summary>
        /// Thing name used for referencing object in game
        /// </summary>
        public String InventoryListing
        {
            get { return this.inventoryListing; }
            set { this.inventoryListing = value; }
        }

        /// <summary>
        /// Thing custom type
        /// </summary>
        public String CustomType
        {
            get { return this.customType; }
            set { this.customType = value; }
        }

        /// <summary>
        /// Thing name used for referencing object the games inventory listing
        /// </summary>
        public String InternalName
        {
            get { return internalName; }
            set { internalName = value; }
        }

        /// <summary>
        /// Thing name used for referencing object in game when in declared as a singular object
        /// </summary>
        public String IndefiniteArticle
        {
            get { return this.indefiniteArticle; }
            set { this.indefiniteArticle = value; }
        }


        /// <summary>
        /// name when there is more than one being referenced
        /// </summary>
        public String PluralName
        {
            get { return pluralName; }
            set { pluralName = value; }
        }


        /// <summary>
        /// Thing object type
        /// </summary>
        public int Type
        {
            get { return type; }
            set { type = value; }
        }


        /// <summary>
        /// Thing name used for printing object reference in game
        /// </summary>
        public String PrintedName
        {
            get { return printedName; }
            set { printedName = value; }
        }

    }
}
